
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%@ page import="java.util.ArrayList,
                com.scalar.chiptrack.jobs.Job,
                com.scalar.chiptrack.jobs.JobRunner,
                 com.scalar.chiptrack.utils.ConfigManager" %>

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>

<chiptrack:checkLogon sourcePage="/jobAdmin.do"/>
<html:html locale="true">

<%String chipTracContext = "/" + ConfigManager.getChipTracContext();%>

<HEAD><TITLE>Scalarsoft - ChipTrac</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type=text/css rel=stylesheet>

<script language='javascript'>
function search() {
    document.maintainUserForm.submit();
}
function loadJobs()
{
    jobform=document.jobAdminForm;
    jobform.submit();
}
</script>

<META content="MSHTML 5.50.4807.2300" name=GENERATOR></HEAD>
<BODY bgColor='#ffffff' leftMargin=0 topMargin=0 marginheight="0" marginwidth="0">

<!-- Top Header Start-->
<%@ include file="/jsp/includes/header.jsp" %>
<!-- Top Header End-->

<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
  <TBODY>
  <TR>
	<td width='180' valign='top' background='<%=chipTracContext%>/jsp/includes/images/left_red_bg.gif'>

<!-- Side Navigation start -->
<%@ include file="/jsp/admin/admin_menu.jsp" %>
<!-- end of the side navigations -->

<TD bgcolor="#ffffff">
<IMG height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8></TD>
<TD bgcolor="#ffffff"><IMG height=480 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=2></TD>
<TD valign="top" width="100%">

<IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/clear.gif" width=500 border=0>
<BR>

<%

// GET ALL OBJECTS ADDED TO REQUEST, BY JOB_ADMIN_ACTION CLASS

// Get JobRunner
JobRunner jobRunner = JobRunner.getInstance();

ArrayList runningJobs = (ArrayList) request.getAttribute ("runningJobs");
if (runningJobs == null) runningJobs = new ArrayList();

ArrayList doneJobs = (ArrayList) request.getAttribute ("doneJobs");
if (runningJobs == null) doneJobs = new ArrayList();
ArrayList schedulableJobs = (ArrayList) request.getAttribute ("schedulableJobs");
if (schedulableJobs == null) schedulableJobs = new ArrayList();
ArrayList statusList = (ArrayList) request.getAttribute ("statusList");
if (statusList == null) statusList = new ArrayList();
%>


<%
//
// ....................... SHOW JOB_RUNNER STATUS AND START/STOP BUTTONS .......................
//
%>

<center><span class="NArialW">Periodic Jobs Run Information</span></center>
<img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20>

<table border="0" width="90%" bordercolor="#FFFFFF" align=right>

<tr><td><IMG height=10 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8></td></tr>

<tr><td><chiptrack:info styleClass='NArialL'/></td></tr>
<tr><td><chiptrack:errors styleClass='NArialL'/></td></tr>

<tr><td><IMG height=10 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8></td></tr>

<tr><td align='left'>
<html:form name="jobAdminForm" type= "com.scalar.chiptrack.jobs.forms.JobAdminForm" method='post' action='/jobAdmin.do'>

    <%
        int jobRunnerStatus = jobRunner.getStatus();
        if (jobRunnerStatus == JobRunner.JOB_RUNNER_STARTED) {
    %>
            <font class="NArialL"><p><font color='green'><b>Job Scheduler</b> is running, since <%=jobRunner.getJobRunnerStartTime()%></font> <input type='submit' name='action' value='Stop Job Scheduler' class="NArialL" onmouseover="window.status='Click to Stop Job Scheduler';return true" onmouseout="window.status='';return true" title="Click here to Stop Job Scheduler"></font>
    <%
        }
        else if (jobRunnerStatus == JobRunner.JOB_RUNNER_STOPPED) {
    %>
            <font class="NArialL"><p><font color='red'><b>Job Scheduler</b> is not running </font><input type='submit' name='action' value='Start Job Scheduler' class="NArialL" onmouseover="window.status='Click to Start Job Scheduler';return true" onmouseout="window.status='';return true" title="Click here to Start Job Scheduler"></font>
    <%
        }
    %>

</td></tr>




<tr><td><IMG height=20 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8></td></tr>
<tr><td align='left'>

</td> </tr>

<tr><td><IMG height=20 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8></td></tr>

<tr><td align='left'>

    <table border='0' width='80%' bordercolor="#FFFFFF" >

        <th align='center' bgcolor='#993333' colspan='6'><font class="NArialL"><font color='#FFFFFF'>Running Jobs Information</font></font>&nbsp;&nbsp;<input type='submit' name='action' value='Refresh' class="NArialL" onmouseover="window.status='Click to Refresh Job Scheduler';return true" onmouseout="window.status='';return true" title="Click here to Refresh Job Scheduler"></th>

        <%
            int runningJobsSize = runningJobs.size();
            if (runningJobsSize == 0) {
        %>
                <tr bgcolor='#DEE1E2' align='center'>
                    <td colspan='6'><font class="NArialL">No Running jobs</font></td>
                </tr>
        <%
            }
            else {
        %>
                <tr bgcolor='#999993' align='center'>
                    <td><font class="NArialL">Job Name</font></td>
                    <td><font class="NArialL">Start Time</font></td>
                    <td><font class="NArialL">status</font></td>
                    <td></td>
                </tr>

                <logic:iterate id="job" name="runningJobs">
                <tr align='center' bgcolor='#DEE1E2'><font class="NArialL">
                    <td> <font class="NArialL"><bean:write name="job" property="name"/></font> </td>
                    <td> <font class="NArialL"><bean:write name="job" property="startTime"/></font> </td>
                    <td> <font class="NArialL"><bean:write name="job" property="status"/></font> </td>
                    <td> <input type='checkbox' name='jobId' value='<bean:write name="job" property="id" />'></td>
                </tr>
                </logic:iterate>
        <%
            }

            if (runningJobsSize != 0) {
        %>
                <tr><td colspan='7' align='right'><input type='submit' name='action' value='Abort' class="NArialL"></td></tr>
        <%
            }
        %>

        </table>
    
    </td></tr>

<tr><td><IMG height=20 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8></td></tr>

<%
// 
//  ....................... SHOW JOB Status .......................
//  
%>
    
<tr><td align='left'>
    <table border='0' width='80%' bordercolor="#FFFFFF" >
      <tr>
        <TD width="20%" class="NArialL">Job Name :</TD>
        </td>
        <td align='left'>
        <nested:select property="jobId"  styleClass="txfield" >
            <html:option value="0">All Jobs</html:option>
            <html:options collection="schedulableJobs" property="id" labelProperty="name"/>
        </nested:select>
      </td>
      <TD width="10%" class="NArialL">&nbsp;</TD>
      <TD width="20%" class="NArialL">Job Status :</TD>
      <td align='left'>
        <nested:select property="status"  styleClass="txfield" >
            <html:option value="All">All Status</html:option>
            <html:options collection="statusList" property="value" labelProperty="label"/>
        </nested:select>
      </td>
      <TD width="5%" class="NArialL">&nbsp;</TD>
      <TD width="20%" class="NArialL"><input type='button' name='action' value='Refresh' class="NArialL" onmouseover="window.status='Click to Refresh Job Scheduler';return true" onmouseout="window.status='';return true" title="Click here to Refresh Job Scheduler" onclick="javaScript:loadJobs()"></TD>
      </tr>
    </table>
    </td>
    </tr>
    <tr><td align='left'>
    <table border='0' width='80%' bordercolor="#FFFFFF" >

        <th align='center' bgcolor='#993333' colspan='6'><font class="NArialL"><font color='#FFFFFF'><nested:write property="status"/> Jobs Information</font></font>&nbsp;&nbsp;</th>

        <%
            int doneJobsSize = doneJobs.size();
            if (doneJobsSize == 0) {
        %>
                <tr bgcolor='#DEE1E2' align='center'>
                    <td colspan='6'><font class="NArialL">No Done/Aborted jobs</font></td>
                </tr>
        <%
            }
            else {
        %>
                <tr bgcolor='#999993' align='center'>
                    <td><font class="NArialL">Job Name</font></td>
                    <td><font class="NArialL">Start Time</font></td>
                    <td><font class="NArialL">End Time</font></td>
                    <td><font class="NArialL">Time Taken (sec)</font></td>
                    <td><font class="NArialL">status</font></td>
                    <td></td>
                </tr>

                <logic:iterate id="job" name="doneJobs">
                <tr align='center' bgcolor='#DEE1E2'><font class="NArialL">
                    <td> <font class="NArialL"><bean:write name="job" property="name"/></font> </td>
                    <td> <font class="NArialL"><bean:write name="job" property="startTime"/></font> </td>
                    <td> <font class="NArialL"><bean:write name="job" property="endTime"/></font> </td>
                    <td> <font class="NArialL"><bean:write name="job" property="timeTaken"/></font> </td>
                    <td> <font class="NArialL"><bean:write name="job" property="status"/></font> </td>
                    <td> <input type='checkbox' name='jobStatusId' value='<bean:write name="job" property="statusId" />'></td>
                </tr>
                </logic:iterate>
        <%
            }

            if (doneJobsSize != 0) {
        %>
                <tr><td colspan='7' align='right'><input type='submit' name='action' value='Remove' class="NArialL" onmouseover="window.status='Click to Remove Job';return true" onmouseout="window.status='';return true" title="Click here to Remove the Job "></td></tr>
        <%
            }
        %>

    </table>

</html:form>

</td></tr>

<tr><td><IMG height=20 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8></td></tr>

</table>


</TD>
<TD bgcolor="#ffffff"><IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=1></TD>
</TR>
</TABLE>

<!-- Footer starts here -->
<%@ include file="/jsp/includes/footer.jsp" %>
<!-- footer end here -->

</body>

</html:html>
